BATT-MON 5 Click
BATT-MON 5 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
Click Library
- Author : Stefan Filipovic
- Date : Sep 2024.
- Type : I2C type
Software Support
Example Description
This example demonstrates the use of BATT-MON 5 Click board by reading the battery cell voltage and the relative state of charge (RSOC).
Example Libraries
- MikroSDK.Board
- MikroSDK.Log
- Click.BATTMON5
Example Key Functions
- battmon5_cfg_setup Config Object Initialization function.
void battmon5_cfg_setup(battmon5_cfg_t *cfg)
BATT-MON 5 configuration object setup function.
BATT-MON 5 Click configuration object.
Definition battmon5.h:201
- battmon5_init Initialization function.
err_t battmon5_init(battmon5_t *ctx, battmon5_cfg_t *cfg)
BATT-MON 5 initialization function.
BATT-MON 5 Click context object.
Definition battmon5.h:184
- battmon5_default_cfg Click Default Configuration function.
err_t battmon5_default_cfg(battmon5_t *ctx)
BATT-MON 5 default configuration function.
- battmon5_write_reg This function writes a data word starting to the selected register by using I2C serial interface.
err_t battmon5_write_reg(battmon5_t *ctx, uint8_t reg, uint16_t data_in)
BATT-MON 5 write reg function.
- battmon5_read_reg This function reads a data word from the selected register by using I2C serial interface.
err_t battmon5_read_reg(battmon5_t *ctx, uint8_t reg, uint16_t *data_out)
BATT-MON 5 read reg function.
- battmon5_get_alarm_pin This function returns the ALARM pin logic state.
uint8_t battmon5_get_alarm_pin(battmon5_t *ctx)
BATT-MON 5 get alarm pin function.
Application Init
Initializes the driver and performs the Click default configuration.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( I2C_MASTER_ERROR ==
battmon5_init( &battmon5, &battmon5_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ BATTMON5_ERROR
Definition battmon5.h:219
#define BATTMON5_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition battmon5.h:171
void application_init(void)
Definition main.c:37
#define MIKROBUS_POSITION_BATTMON5
Definition main.c:31
Application Task
Reads the battery cell voltage and the relative state of charge (RSOC) and displays the results on the USB UART approximately once per second.
{
uint16_t voltage = 0;
uint16_t rsoc = 0;
{
log_printf ( &logger, " Voltage: %u mV\r\n", voltage );
}
{
log_printf ( &logger, " RSOC: %u %%\r\n\n", rsoc );
}
Delay_ms ( 1000 );
}
@ BATTMON5_OK
Definition battmon5.h:218
#define BATTMON5_REG_RSOC
Definition battmon5.h:81
#define BATTMON5_REG_CELL_V
Definition battmon5.h:77
void application_task(void)
Definition main.c:73
Note
For the communication with the Click board to work, the battery needs to be connected. The Click board is configured by default for a 2000 mAh battery pack capacity.
Application Output
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Additional Notes and Information
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.